package dataDraw.classDiagramDraw;

import dataDraw.Constants;
import tools.Point;

import java.awt.*;

/**
 * User: Szymon Kudzia
 * Date: 29.04.13
 * Time: 14:56
 */
public class GradientEntityConnectionDraw extends BasicEntityConnectionDraw {
	protected Color startColor;
	protected Color endColor;

	@Override
	protected void drawHorizontalTriangle(Point p2, int y_before_triangle) {
		int x[] = {p2.x - Constants.TRIANGLE_HALF_A,
				   p2.x + Constants.TRIANGLE_HALF_A,
				   p2.x};
		int y[] = {y_before_triangle,
				   y_before_triangle,
				   p2.y};

		fiilPolygon(x, y);

		super.drawHorizontalTriangle(p2, y_before_triangle);
	}

	private void fiilPolygon(int[] x, int[] y) {
		Graphics2D g2d = (Graphics2D)g;

		GradientPaint gp = new GradientPaint(x[0], y[2], startColor, x[1], y[0], endColor);
		g2d.setPaint(gp);
		g2d.fillPolygon(x, y, x.length);
		g2d.setColor(Color.black);
	}

	@Override
	protected void drawVerticalTriangle(Point p2, int x_before_triangle) {
		int x[] = {x_before_triangle,
				x_before_triangle,
				p2.x};
		int y[] = {p2.y - Constants.TRIANGLE_HALF_A,
				p2.y + Constants.TRIANGLE_HALF_A,
				p2.y};

		fiilPolygon(x, y);

		super.drawVerticalTriangle(p2, x_before_triangle);
	}

	@Override
	protected Point drawRightRhomb(Point p) {
		int x[] = {p.x,
				p.x + Constants.RHOMB_H1,
				p.x + 2 * Constants.RHOMB_H1,
				p.x + Constants.RHOMB_H1};
		int y[] = {p.y,
				p.y - Constants.RHOMB_H2,
				p.y,
				p.y + Constants.RHOMB_H2};

		fiilPolygon(x, y);

		return super.drawRightRhomb(p);
	}

	@Override
	protected Point drawLeftRhomb(Point p) {
		int x[] = {p.x - 2 * Constants.RHOMB_H1,
				p.x - Constants.RHOMB_H1,
				p.x,
				p.x - Constants.RHOMB_H1};
		int y[] = {p.y,
				p.y - Constants.RHOMB_H2,
				p.y,
				p.y + Constants.RHOMB_H2};

		fiilPolygon(x, y);

		return super.drawLeftRhomb(p);
	}

	public void setStartColor(Color startColor) {
		this.startColor = startColor;
	}

	public void setEndColor(Color endColor) {
		this.endColor = endColor;
	}
}
